home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* DATABOSS MODULE: DB_GVAR */
- /* */
- /* Please update this commentary when changes have been made */
- /* */
- /* */
- /* Date Version Person Description */
- /* ------------------------------------------------------------------------ */
- /* 24/05/91 3.51 SN Added code to 'initThisProg' to */
- /* remove double backslashes '\' */
- /****************************************************************************/
-
- #include "db_lsc.h"
-
-
- #ifdef __TURBOC__
- #include <conio.h>
- #else
- #include <graph.h>
- #endif
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "db_types.h"
- #include "db_conio.h"
- #include "db_dos.h"
- #include "db_dmem.h"
- #include "db_file.h"
- #include "db_str.h"
- #include "db_gvar.h"
-
- /**************************** GLOBAL CONSTANTS ****************************/
-
- const uchar recog[] = "DBGV";
-
- /**************************** GLOBAL VARIABLES ****************************/
-
- bool i_alloc;
- grecptr dgvar;
- dbossgv *gvar;
- fspec thisprog;
- bool dbcaller;
- string lookalong;
-
- /*************************** INTERNAL VARIABLES ***************************/
-
- static bool initialized = False;
-
- /***************************** IMPLEMENTATION *****************************/
-
- ptr string2pointer(str8 s)
- {
- int i;
- ptr p;
- byte x[4];
-
- for (i=0; i<4; i++)
- x[i] = (s[i*2] & 0x0F) | ((s[i*2+1] & 0x0F) << 4);
- memmove(&p,x,4);
- return (p);
- }
-
- strptr pointer2string(strptr sout,ptr p)
- {
- int i;
- byte x[4];
-
- memmove(x,&p,4);
- for (i=0; i<4; i++) {
- sout[i*2] = (x[i] & 0x0F) | 0x30;
- sout[i*2+1] = (x[i] >> 4) | 0x30;
- }
- sout[8] = 0;
- return (sout);
- }
-
- void pascal2c(string instr, int max)
- {
- byte l;
-
- l = instr[0];
- if (l <= ((byte)(max-1)))
- memmove(instr,&instr[1],l);
- else
- l = 0;
- instr[l] = '\0';
- }
-
- void initthisprog(void)
- {
- if (_osmajor >= 3)
- strcpy(thisprog.fpath,paramstr(0));
- else {
- getcurrentdir(thisprog.fpath, 0);
- if (*(thisprog.fpath + 2) == '\\') strcat(thisprog.fpath, "UKNOWN.EXE");
- else strcat(thisprog.fpath, "\\UKNOWN.EXE");
- }
- fsplit(thisprog.fpath,thisprog.fdir,thisprog.fname,thisprog.fext);
- }
-
- bool initgvar(idstr chkid, word size, grecptr *dgv, bool *ia)
- {
- int i;
- long tsz;
- string ts,tmp;
-
- *dgv = NULL;
- i = 1;
- while ((*dgv == NULL) && (i < paramcount())) {
- strcpy(ts,paramstr(i));
- if (strcmp(strcopy(tmp,ts,0,strlen(recog)),recog) == 0) {
- strdelete(ts,0,strlen(recog));
- *dgv = string2pointer(ts);
- memmove(ts,(*dgv)->id,sizeof((*dgv)->id)); pascal2c(ts,sizeof(ts));
- if ((strcmp((*dgv)->id,chkid) == 0) || (strcmp(ts,chkid) == 0))
- *ia = False;
- else
- *dgv = NULL;
- }
- i++;
- }
- if (*dgv == NULL) {
- tsz = sizeof(grecord) + size - 1;
- *dgv = dosmallochigh(tsz);
- if (*dgv != NULL) {
- strcpy((*dgv)->id,chkid);
- (*dgv)->gsize = tsz;
- *ia = True;
- }
- }
- return ((bool) (*dgv != NULL));
- }
-
- void initdboss(grecptr dgv)
- {
- gvar = (dbossgv *) &(dgv->gdata);
- if (i_alloc) {
- strcpy(gvar->operator,"********");
- strcpy(gvar->fname,thisprog.fname);
- gvar->sec = 0;
- strcpy(gvar->company,"Kedwell Software Pty. Ltd.");
- gvar->prog[0] = '\0';
- gvar->language = 'C';
- dbcaller = False;
- }
- else {
- dbcaller = True;
- if (gvar->language == 'P') {
- pascal2c(gvar->operator,sizeof(gvar->operator));
- pascal2c(gvar->fname,sizeof(gvar->fname));
- pascal2c(gvar->company,sizeof(gvar->company));
- pascal2c(gvar->prog,sizeof(gvar->prog));
- gvar->language = 'C';
- }
- }
- }
-
- /********************** UNIT INITIALIZATION/EXIT CODE *********************/
-
- void db_gvar_exit(void)
- {
- if (i_alloc)
- dosfree(dgvar);
- }
-
- void db_gvar_init(void)
- {
- string p1,p2;
-
- if (!initialized) {
- initialized = True;
- if (!(initgvar("DATABOSS",sizeof(dbossgv),&dgvar,&i_alloc))) {
- cwrite(_NoGlobalSpace);
- cwrite("\n\r");
- exit(0);
- }
- else {
- initthisprog();
- initdboss(dgvar);
- atexit(db_gvar_exit);
- }
- strconcat(lookalong,getenvstr(p1,"DBPATH"),";",getenvstr(p2,"PATH"),";",thisprog.fdir,NULL);
- }
- }
-
- /***************************** END OF DB_GVAR.C ****************************/
-